package com.example.listener;

import com.example.config.RabbitMQConfig;
import com.example.model.UserEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class UserEventListener {
    
    @RabbitListener(queues = RabbitMQConfig.USER_QUEUE)
    public void handleUserEvent(UserEvent event) {
        log.info("Received user event: {}", event);
        
        // 处理用户事件的业务逻辑
        switch (event.getAction()) {
            case "CREATED":
                log.info("User created: {}", event.getUsername());
                break;
            case "UPDATED":
                log.info("User updated: {}", event.getUsername());
                break;
            case "DELETED":
                log.info("User deleted: {}", event.getUsername());
                break;
            default:
                log.warn("Unknown user action: {}", event.getAction());
        }
    }
} 